#include "opacitywidget.h"

#include <QPainter>

opacitywidget::opacitywidget(QWidget *parent)
    : QWidget(parent)
{
    m_opacity = 1;
}

opacitywidget::~opacitywidget()
{
}

void opacitywidget::setOpacity(qreal opacity)
{
    m_opacity = opacity;
    update();//调用paintEvent
}

void opacitywidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);//以当前窗口为绘图设备
    painter.setOpacity(m_opacity);//设置不透明度
    painter.setBrush(m_color);//设置笔刷颜色
    painter.setPen(Qt::NoPen);
    painter.drawRect(rect());//设置画的范围
}
